import java.sql.*;

public class b{
    public static void main(String args[]){
        String query = "SELECT * FROM TEACHERS";
        String db = "HOMEWORK";
        String username = "root";
        String password = "winter";
        String url = "jdbc:mysql://localhost/"
                    + db +"?useUnicode=true&characterEncoding=UTF-8";

        try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection(url, username, password);
            //get a connection
            Statement stmt=con.createStatement();
            ResultSet rs = stmt.executeQuery(query);
            ResultSetMetaData rsmd = rs.getMetaData();
            int columnCount = rsmd.getColumnCount();
            for (int i = 0; i < columnCount; i ++)
                //System.out.print(rsmd.getColumnLabel(i+1) + "\t" );
                System.out.print(rsmd.getColumnName(i+1) + "\t\t\t" );
            System.out.println("");
            while(rs.next()){
                for (int i = 0; i < columnCount; i ++)
                    System.out.print(rs.getString(i+1) + "\t\t");
                System.out.println("");
            }
            con.close();
        }catch(ClassNotFoundException e){
            System.out.println("Could not found the driver class");
            e.printStackTrace();
        }catch(SQLException e){
            System.out.println("Something wrong about the SQL");
            e.printStackTrace();
        }
    }
}


